#include <bits/stdc++.h>

#include <atcoder/all>
#define LL long long
using namespace std;
using namespace atcoder;

const int kMaxN = 20;
const int kInf = 1e9;

struct Shift {
  int s, no;
  int childu, childv, candy;

  Shift() {
    s = no = childu = childv = candy = -1;
  }

  void Output() {
    cout << childu + 1 << " " << childv + 1 << " " << candy << "\n";
  }
} path[1 << kMaxN][kMaxN];

int f[1 << kMaxN][kMaxN];
int news[1 << kMaxN];
LL sum[1 << kMaxN];

LL A[kMaxN], avg = 0;

void Renew(int ns, int nj, int f_val, Shift sh) {
  if (f[ns][nj] > f_val) {
    f[ns][nj] = f_val;
    path[ns][nj] = sh;
  }
}

void DP(int n) {
  for (int i = 0; i < (1 << n); i++) {
    for (int j = 0; j < n; j++) {
      f[i][j] = kInf;
      if ((i & (1 << j)) == 0) {
        news[i] = j;
      }
    }
  }
  for (int i = 0; i < n; i++) {
    A[i] -= avg;
  }
  for (int i = 1; i < (1 << n); i++) {
    for (int j = 0; j < n; j++) {
      if (i & (1 << j)) {
        sum[i] = sum[i ^ (1 << j)] + A[j];
        break;
      }
    }
  }

  int s = 0, p = 0;
  for (int i = 0; i < n; i++) {
    if (A[i] == 0) {
      s |= (1 << i);
    } else {
      p = i;
    }
  }
  f[s][p] = 0;

  for (int i = 0; i < (1 << n); i++) {
    for (int j = 0; j < n; j++) {
      if (f[i][j] == kInf) {
        continue;
      }

      for (int k = 0; k < n; k++) {
        LL dk = A[k], dj = sum[i | (1 << j)];
        if ((i & (1 << k)) == 0 && k != j && dk * dj < 0) {
          LL delta = min(abs(dj), abs(dk));
          Shift tmps;

          tmps.s = i;
          tmps.no = j;
          tmps.candy = delta;
          if (dk < 0) {
            tmps.childu = j;
            tmps.childv = k;
            dk += delta;
            dj -= delta;
          } else {
            tmps.childu = k;
            tmps.childv = j;
            dk -= delta;
            dj += delta;
          }

          if (dk == 0 && dj == 0) {
            int ns = i | (1 << k) | (1 << j);
            int l = news[ns];

            Renew(ns, l, f[i][j] + 1, tmps);
          } else if (dk == 0) {
            Renew(i | (1 << k), j, f[i][j] + 1, tmps);
          } else {  // dj==0
            Renew(i | (1 << j), k, f[i][j] + 1, tmps);
          }
        }
      }
    }
  }
}

void OutputPath(int n) {
  int nows = (1 << n) - 1, nowno = 0;

  cout << f[nows][nowno] << "\n";
  while (f[nows][nowno]) {
    int nexts = path[nows][nowno].s;
    int nextno = path[nows][nowno].no;

    path[nows][nowno].Output();
    nows = nexts;
    nowno = nextno;
  }
}

int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> A[i];
    avg += A[i];
  }
  if (avg % n != 0) {
    cout << "-1\n";
    return 0;
  }
  avg /= n;
  DP(n);
  OutputPath(n);
  return 0;
}
